package it.polimi.entities;

import java.io.Serializable;

import javax.persistence.*;

import java.sql.Time;
import java.util.List;

import it.polimi.authentication.ejb.usermanagement.*;
import it.polimi.entitiesDTO.AttractionDTO;

/**
 * The persistent class for the attraction database table.
 * 
 */
@Entity
@NamedQueries ({ @NamedQuery(name=Attraction.FIND_ALL, query="SELECT a FROM Attraction a"),
				 @NamedQuery(name=Attraction.FIND_ATTRACTION, query="SELECT a FROM Attraction a WHERE a.id = :id"),
				 @NamedQuery(name=Attraction.FIND_ATTRACTION_BY_CITY, query="SELECT a FROM Attraction a WHERE a.city = :city"),
				 @NamedQuery(name=Attraction.FIND_ALL_ID, query="SELECT a.id FROM Attraction a")

})

public class Attraction implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "Attraction.findAll";
	
	public static final String FIND_ATTRACTION = "Attraction.findAttraction";
	
	public static final String FIND_ATTRACTION_BY_CITY = "Attraction.findAttractionByCity";

	public static final String FIND_ALL_ID = "Attraction.findAllId";


	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	private String city;

	@Lob
	private String description;

	private Time duration;

	private int price;

	private int spots;

	private boolean visibility;

	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="employee")
	private User user;
	
	//bi-directional many-to-one association to PacketAttraction
		@OneToMany(mappedBy="attractionBean")
		private List<PacketAttraction> packetAttractions;



	public Attraction() {
		super();
	}
	
	public Attraction(AttractionDTO attraction){
		
		this.id = attraction.getID();
		this.city = attraction.getCity();
		this.description = attraction.getDescription();
		this.duration = attraction.getDuration();
		this.price = attraction.getPrice();
		this.spots = attraction.getSpots();
		this.visibility = attraction.isVisibility();
		
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Time getDuration() {
		return this.duration;
	}

	public void setDuration(Time duration) {
		this.duration = duration;
	}

	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public int getSpots() {
		return this.spots;
	}

	public void setSpots(int spots) {
		this.spots = spots;
	}

	public boolean getVisibility() {
		return this.visibility;
	}

	public void setVisibility(boolean visibility) {
		this.visibility = visibility;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}


	public List<PacketAttraction> getPacketAttractions() {
		return this.packetAttractions;
	}

	public void setPacketAttractions(List<PacketAttraction> packetAttractions) {
		this.packetAttractions = packetAttractions;
	}

	public PacketAttraction addPacketAttraction(PacketAttraction packetAttraction) {
		getPacketAttractions().add(packetAttraction);
		packetAttraction.setAttractionBean(this);

		return packetAttraction;
	}

	public PacketAttraction removePacketAttraction(PacketAttraction packetAttraction) {
		getPacketAttractions().remove(packetAttraction);
		packetAttraction.setAttractionBean(null);

		return packetAttraction;
	}
	
	public String toString (){
		return "ID: " + this.getId() + " City: " + this.getCity() + " Description: " + this.getDescription();
		}
	
}